<?php

namespace App\Admin\Controllers\Merchant;

use App\Admin\Repositories\SwtUser;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class SwtUserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SwtUser(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('mobile');
            $grid->column('status')->switch();
            $grid->column('source_type','来源')->using(['微信','支付宝'])->label(['success','info']);
            $grid->column('created_at') -> format('Y-m-d H:i:s');
            $grid->column('updated_at') -> format('Y-m-d H:i:s');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('mobile');
            });

            $grid->actions( function (Grid\Displayers\Actions $actions) {
               $actions->quickEdit();
            });


            $grid->quickSearch('mobile');
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtUser(), function (Form $form) {
            $form->display('id');
            $form->image('avatar')->move('upload/avatar')->uniqueName()->autoUpload();
            $form->switch('status');
        });
    }
}
